package cn.stylefeng.guns.modular.cb.service.impl;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.cb.entity.CbCollegeProfessional;
import cn.stylefeng.guns.modular.cb.mapper.CbCollegeProfessionalMapper;
import cn.stylefeng.guns.modular.cb.model.params.CbCollegeProfessionalParam;
import cn.stylefeng.guns.modular.cb.model.result.CbCollegeProfessionalResult;
import  cn.stylefeng.guns.modular.cb.service.CbCollegeProfessionalService;
import cn.stylefeng.roses.core.util.ToolUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.List;

/**
 * <p>
 *  基础信息-学校-专业 服务实现类
 * </p>
 *
 * @author wj
 * @since 2021-01-06
 */
@Service
public class CbCollegeProfessionalServiceImpl extends ServiceImpl<CbCollegeProfessionalMapper, CbCollegeProfessional> implements CbCollegeProfessionalService {

    @Override
    public void add(CbCollegeProfessionalParam param){
        CbCollegeProfessional entity = getEntity(param);
        this.save(entity);
    }

    @Override
    public void delete(CbCollegeProfessionalParam param){
        this.removeById(getKey(param));
    }

    @Override
    public void update(CbCollegeProfessionalParam param){
        CbCollegeProfessional oldEntity = getOldEntity(param);
        CbCollegeProfessional newEntity = getEntity(param);
        ToolUtil.copyProperties(newEntity, oldEntity);
        this.updateById(newEntity);
    }

    @Override
    public CbCollegeProfessionalResult findBySpec(CbCollegeProfessionalParam param){
        return null;
    }

    @Override
    public List<CbCollegeProfessionalResult> findListBySpec(CbCollegeProfessionalParam param){
        return this.baseMapper.customList(param);
    }

    @Override
    public LayuiPageInfo findPageBySpec(CbCollegeProfessionalParam param){
        Page pageContext = getPageContext();
        IPage page = this.baseMapper.customPageList(pageContext, param);
        return LayuiPageFactory.createPageInfo(page);
    }

    private Serializable getKey(CbCollegeProfessionalParam param){
        return param.getId();
    }

    private Page getPageContext() {
        return LayuiPageFactory.defaultPage();
    }

    private CbCollegeProfessional getOldEntity(CbCollegeProfessionalParam param) {
        return this.getById(getKey(param));
    }

    private CbCollegeProfessional getEntity(CbCollegeProfessionalParam param) {
        CbCollegeProfessional entity = new CbCollegeProfessional();
        ToolUtil.copyProperties(param, entity);
        return entity;
    }

}
